define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_detail(result) {
			if(false) {
				result = '{"success": true,"msg": "",' +
					'"result": {"act_id": "001","name": "促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","create_group": true,"has_packets": true,"image": [{"id": "001","image": ""},{"id": "002","image": ""}],"brand_id": "001","cat_type": [{"id": "001"},{"id": "002"}]},' +
					'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_groupbuy_goods_detail(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"act_id":"001","act_name":"五金团购","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","introduction":"五金货品团购促销，买的越多，省的越多。","group_id":"123456789","image":[{"id":"001","image":"./img/upload/siwper-img00.png"},{"id":"002","image":"./img/upload/siwper-img01.png"},{"id":"003","image":"./img/upload/siwper-img02.png"}],"goods":[{"id":"001","goods_name":"一字螺丝刀","image":[{"id":"001","image":""},{"id":"001","image":""}],"groupbuy_rule":[{"id":"001","count":1000,"promotion_price":"9.5","days":1},{"id":"002","count":2000,"promotion_price":"8.5","days":1}],"promotion_price":10,"limit_buy_num":10},{"id":"002","goods_name":"十字螺丝刀","image":"001.jpg","price":10.5,"deposit":10,"groupbuy_rule":[{"id":"001","count":1000,"promotion_price":"9.5","days":1},{"id":"002","count":2000,"promotion_price":"8.5","days":10}],"promotion_price":10,"limit_buy_num":10}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		function get_data_groupbuy_detail(result){
			if(false){
				result = '{"success":true,"msg":"","result":{"act_id":"001","act_name":"五金团购","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","introduction":"五金货品团购促销，买的越多，省的越多。","group_id":"123456789","image":[{"id":"001","image":"./img/upload/siwper-img00.png"},{"id":"002","image":"./img/upload/siwper-img01.png"},{"id":"003","image":"./img/upload/siwper-img02.png"}],"goods":[{"id":"001","name":"精工锤子","image":{"id":"001","image":""},"store":23},{"id":"002","name":"精工螺丝","image":{"id":"002","image":""},"store":230}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			}else
			return result;
		}
		function get_data_group_buy(result){
			if(false){
				result = '{"success": true,"msg": "","result": {"act_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			}else
			return result;
		}
		//返回信息
		return {
			//获取相应数据
			get_detail: function(act_id, callback, calldone) {
				Http.post({
					"method": "marketing.groupbuy.detail",
					"act_id": act_id
				}, function(result) {
					if(callback)
						callback(get_data_detail(result).result);
				}, function(err) {

				}, function() {
					if(calldone)
						calldone();
				});
			},
			
			groupbuy_goods_detail: function(act_id, callback) {
				Http.post({
					method: 'marketing.groupbuy.viewdetail',
					act_id: act_id,
//					product_id: product_id,
					picSize: 'CS'
				}, function(result) {
					if(callback)
						callback(get_data_groupbuy_goods_detail(result),result.process_time);
				}, function(e) {

				}, function() {

				})
			},
			groupbuy_detail:function(act_id,callback){
				Http.post({
					method:'marketing.groupbuy.view',
					act_id:act_id,
					picSize:'CS'
				},function(result){
					if(callback)
					callback(get_data_groupbuy_detail(result).result);
				},function(e){
					
				},function(){
					
				})
			},
			get_loginfo:function(callback){
				Http.post({
					method:'chat.group.getlogininfo'
				},function(result){
					if(callback)
					callback(result.result);
				})
			}
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Groupbuydetail", factory);
});